package list;

import java.util.Arrays;

/**
 * @ClassName: ListNode
 * @Author: wangyusong
 * @Date: 2020-10-06 22:01
 * @Desciprion: 顺序表的结构及基本操作
 * @Version:
 */
public abstract class  ListNode<T> implements ListInterface{
    private int length;
    private Object[] list;

    public ListNode() {
    }
    /**
     * 初始化表
     * */
    @Override
    public void initList(int max){
        this.list = new Object[max];
        this.length= 0;
    }
    /**
     * 在指定位置插入元素e
    * */
    @Override
    public boolean listInsert(Object[] list, int i, Object e) {
        /*判断i的范围是否有效*/
        if (i<1 || i>this.list.length+1){
            return false;
        }
        /*判断表满*/
        if (this.length == this.list.length){
            return false;
        }
        for (int j = this.length;j>=i;j--){
            list[j]=list[j-1];
        }
        this.list[i-1] = e;
        this.length++;
        return true;
    }

    @Override
    public String toString() {
        return "ListNode{" +
                "length=" + length +
                ", list=" + Arrays.toString(list) +
                '}';
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public Object[] getList() {
        return list;
    }

    public void setList(Object[] list) {
        this.list = list;
    }
}
